home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
scilab
/
tests
/
metanet.dia.ref
< prev
next >
Wrap
Text File
|
1999-09-16
|
13KB
|
836 lines
// adj_lists
ta=[2 3 3 5 3 4 4 5 8];
he=[1 2 4 2 6 6 7 7 4];
gt=make_graph('foo',1,8,ta,he);
[lp,la,ls]=adj_lists(1,gt('node_number'),ta,he)
ls =
! 1. 2. 4. 6. 6. 7. 2. 7. 4. !
la =
! 1. 2. 3. 5. 6. 7. 4. 8. 9. !
lp =
! 1. 1. 2. 5. 7. 9. 9. 9. 10. !
// circuit
g=make_graph('foo',1,3,[1 2 3],[2 3 1]);
circuit(g)
ans =
! 1. 2. 3. !
g=make_graph('foo',1,4,[1 2 2 3],[2 3 4 4]);
[p,r]=circuit(g)
r =
! 0. 1. 2. 3. !
p =
[]
// con_nodes
ta=[1 1 2 2 2 3 4 4 5 7 7 9 10 12 12 13 13 14 15];
he=[2 6 3 4 5 1 3 5 1 8 9 8 11 10 11 11 15 13 14];
gt=make_graph('foo',1,15,ta,he);
con_nodes(2,gt)
ans =
! 7. 8. 9. !
// connex
ta=[1 1 2 2 2 3 4 4 5 6 7 7 7 8 9 10 12 12 13 13 14 15];
he=[2 6 3 4 5 1 3 5 1 7 5 8 9 5 8 11 10 11 11 15 13 14];
gt=make_graph('foo',1,15,ta,he);
[nc,ncomp]=connex(gt)
ncomp =
column 1 to 11
! 1. 1. 1. 1. 1. 1. 1. 1. 1. 2. 2. !
column 12 to 15
! 2. 2. 2. 2. !
nc =
2.
// find_path
ta=[1 1 2 2 2 3 4 5 5 7 8 8 9 10 10 10 11 12 13 13 13 14 15 16 16 17 17];
he=[2 10 3 5 7 4 2 4 6 8 6 9 7 7 11 15 12 13 9 10 14 11 16 1 17 14 15];
gt=make_graph('foo',1,17,ta,he);
p=find_path(1,14,gt)
p =
! 2. 16. 23. 25. 26. !
// is_connex
g=make_graph('foo',1,3,[1,2,3,1],[2,3,1,3]);
is_connex(g)
ans =
1.
g=make_graph('foo',1,4,[1,2,3,1],[2,3,1,3]);
is_connex(g)
ans =
0.
// mat_2_graph
g=load_graph(SCI+'/demos/metanet/colored');
a=graph_2_mat(g)
a =
( 10, 21) sparse matrix
( 1, 17) 1.
( 1, 18) - 1.
( 2, 4) 1.
( 2, 5) - 1.
( 2, 11) - 1.
( 2, 12) 1.
( 2, 19) - 1.
( 3, 1) - 1.
( 3, 2) 1.
( 3, 5) 1.
( 3, 9) - 1.
( 4, 14) - 1.
( 4, 15) 1.
( 4, 17) - 1.
( 4, 20) 1.
( 5, 9) 1.
( 5, 10) - 1.
( 5, 12) - 1.
( 5, 13) 1.
( 6, 2) - 1.
( 6, 3) 1.
( 6, 4) - 1.
( 6, 6) - 1.
( 6, 7) 1.
( 7, 6) 1.
( 7, 8) - 1.
( 7, 20) - 1.
( 7, 21) 1.
( 8, 11) 1.
( 8, 13) - 1.
( 8, 14) 1.
( 8, 16) - 1.
( 8, 18) 1.
( 9, 7) - 1.
( 9, 8) 1.
( 9, 15) - 1.
( 9, 16) 1.
( 9, 19) 1.
( 10, 1) 1.
( 10, 3) - 1.
( 10, 10) 1.
( 10, 21) - 1.
g1=mat_2_graph(a,1)
g1 =
g1>1
graph
g1>2
foo
g1>3
1.
g1>4
10.
g1>5
column 1 to 11
! 10. 3. 6. 2. 3. 7. 6. 9. 5. 10. 8. !
column 12 to 21
! 2. 5. 8. 4. 9. 1. 8. 9. 4. 7. !
g1>6
column 1 to 11
! 3. 6. 10. 6. 2. 6. 9. 7. 3. 5. 2. !
column 12 to 21
! 5. 8. 4. 9. 8. 4. 1. 2. 7. 10. !
g1>7
[]
g1>8
[]
g1>9
[]
g1>10
[]
g1>11
[]
g1>12
[]
g1>13
[]
g1>14
[]
g1>15
[]
g1>16
[]
g1>17
[]
g1>18
[]
g1>19
[]
g1>20
[]
g1>21
[]
g1>22
[]
g1>23
[]
g1>24
[]
g1>25
[]
g1>26
[]
g1>27
[]
g1>28
[]
g1>29
[]
g1>30
[]
g1>31
[]
g1>32
[]
g1>33
[]
g1>34
[]
// max_cap_path
ta=[1 1 2 2 2 3 4 5 5 7 8 8 9 10 10 10 11 12 13 13 13 14 15 16 16 17 17];
he=[2 10 3 5 7 4 2 4 6 8 6 9 7 7 11 15 12 13 9 10 14 11 16 1 17 14 15];
gt=make_graph('foo',1,17,ta,he);
ma=gt('edge_number');
gt('edge_max_cap')=[8 17 5 10 15 15 18 15 19 6 13 15 16 8 13 8 8 8 19 15 9 19 8 10 10 9 14];
[p,cap]=max_cap_path(1,14,gt)
cap =
8.
p =
! 2. 15. 17. 18. 21. !
// max_flow
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1];
gt=make_graph('foo',1,15,ta,he);
g1=gt; ma=g1('edge_number');
g1('edge_min_cap')=0*ones(1,ma);
rand('uniform');
g1('edge_max_cap')=[10.7 7.6 12.9 11.0 9.7 6.4 13.7 9.1 19.4 1.9 10.6 6.3 9.3 6.6 3.6 16.6 5.2 3.2 14.7 4.1 14.9 17.8 9.1 9.2 18.6 3.3 5.0 12.2 12.8];
[v,phi]=max_flow(15,1,g1)
phi =
column 1 to 11
! 0. 0. 0. 0. 0. 3. 3. 0. 5. 0. 4. !
column 12 to 22
! 0. 0. 0. 0. 5. 5. 0. 0. 0. 9. 0. !
column 23 to 29
! 0. 9. 12. 3. 4. 0. 4. !
v =
12.
// min_lcost_cflow
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1];
gt=make_graph('foo',1,15,ta,he);
g1=gt;ma=g1('arc_number');
g1('edge_min_cap')=0*ones(1,ma);
g1('edge_max_cap')=[15 8 16 6 9 7 19 4 14 7 17 10 12 6 9 10 9 14 6 17 14 8 8 15 17 18 16 8 16];
g1('edge_cost')=[10.7 3.6 8.4 9.3 7.6 10.7 4.9 6.8 2.3 6.0 5.5 3.0 5.0 1.9 2.6 6.1 7.4 2.3 9.2 10.8 3.2 4.4 8.9 2.8 3.9 8.2 4.0 9.8 2.1];
cv=5;
[c,phi,v,flag]=min_lcost_cflow(15,1,cv,g1)
flag =
1.
v =
5.
phi =
column 1 to 11
! 0. 0. 0. 0. 0. 0. 0. 4. 4. 0. 1. !
column 12 to 22
! 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. !
column 23 to 29
! 0. 1. 5. 4. 1. 0. 1. !
c =
106.3
// min_lcost_flow1
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10 1 8];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1 12 14];
gt=make_graph('foo',1,15,ta,he);
g1=gt;ma=g1('arc_number');
g1('edge_min_cap')=[17 11 10 5 2 5 16 3 20 15 11 4 6 5 5 3 2 8 0 4 14 1 11 14 13 17 3 3 20 2 17];
g1('edge_max_cap')=[37 36 37 25 26 42 35 23 56 52 43 40 42 26 42 33 24 27 34 23 45 29 49 48 45 42 25 24 56 34 45];
g1('edge_cost')=[8 7 3 2 6 10 6 3 5 10 7 11 2 8 1 2 2 4 8 4 4 4 6 8 9 7 5 11 8 2 8];
[c,phi,flag]=min_lcost_flow1(g1)
flag =
1.
phi =
column 1 to 10
! 20. 25. 10. 8. 2. 26. 16. 9. 20. 22. !
column 11 to 20
! 11. 4. 6. 11. 5. 3. 24. 8. 17. 4. !
column 21 to 30
! 14. 1. 13. 28. 13. 17. 12. 17. 20. 21. !
column 31
! 32. !
c =
2863.
// min_lcost_flow2
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10 1 8];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1 12 14];
gt=make_graph('foo',1,15,ta,he);
g1=gt;ma=g1('arc_number');
g1('edge_min_cap')=0.*ones(1,ma);
n=g1('node_number');
g1('edge_max_cap')=[32 19 15 33 32 27 32 32 27 27 34 21 18 33 24 32 15 18 19 30 34 24 25 22 17 29 15 27 15 27 29];
g1('edge_cost')=[2 11 5 2 5 7 8 8 4 5 2 4 2 7 10 2 10 8 8 4 4 6 5 5 7 8 7 6 7 6 5];
dd=[14 -20 -4 8 -3 16 5 -23 0 7 -5 16 4 -24 9];
g1('node_demand')=dd;
[c,phi,flag]=min_lcost_flow2(g1)
flag =
1.
phi =
column 1 to 11
! 0. 14. 13. 6. 1. 17. 0. 0. 27. 5. 7. !
column 12 to 22
! 0. 0. 0. 0. 23. 0. 0. 0. 0. 9. 0. !
column 23 to 31
! 9. 22. 0. 2. 14. 5. 0. 16. 0. !
c =
979.
// min_qcost_flow
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10 1 8];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1 12 14];
gt=make_graph('foo',1,15,ta,he);
g1=gt;ma=g1('arc_number');
g1('edge_min_cap')=[3 4 3 0 2 4 1 4 2 0 1 1 4 4 4 1 3 4 1 3 0 3 0 3 1 1 0 2 0 3 5];
g1('edge_max_cap')=[19 9 15 6 16 16 20 22 12 16 13 16 23 16 14 7 15 21 4 15 8 24 2 10 4 4 20 14 11 18 9];
g1('edge_q_orig')=0*ones(1,ma);
g1('edge_q_weight')=ones(1,ma);
[c,phi,flag]=min_qcost_flow(0.2,g1)
flag =
1.
phi =
column 1 to 11
! 7. 4. 3. 2. 2. 4. 1. 4. 11. 12. 3. !
column 12 to 22
! 1. 4. 4. 4. 1. 3. 4. 1. 3. 0. 3. !
column 23 to 31
! 1. 4. 1. 3. 12. 11. 0. 4. 6. !
c =
413.5
// min_weight_tree
ta=[1 1 2 2 2 3 4 5 5 7 8 8 9 10 10 10 11 12 13 13 13 14 15 16 16 17 17];
he=[2 10 3 5 7 4 2 4 6 8 6 9 7 7 11 15 12 13 9 10 14 11 16 1 17 14 15];
gt=make_graph('foo',1,17,ta,he);
t=min_weight_tree(1,gt)
t =
column 1 to 11
! 1. 3. 6. 4. 9. 5. 10. 12. 2. 15. 17. !
column 12 to 16
! 18. 21. 16. 23. 25. !
// nodes_2_path
ta=[1 1 2 2 2 3 4 5 5 7 8 8 9 10 10 10 11 12 13 13 13 14 15 16 16 17 17];
he=[2 10 3 5 7 4 2 4 6 8 6 9 7 7 11 15 12 13 9 10 14 11 16 1 17 14 15];
gt=make_graph('foo',1,17,ta,he);
ns=[1 10 15 16 17 14 11 12 13 9 7 8 6];
p=nodes_2_path(ns,gt)
p =
column 1 to 10
! 2. 16. 23. 25. 26. 22. 17. 18. 19. 13. !
column 11 to 12
! 10. 11. !
// path_2_nodes
ta=[1 1 2 2 2 3 4 5 5 7 8 8 9 10 10 10 11 12 13 13 13 14 15 16 16 17 17];
he=[2 10 3 5 7 4 2 4 6 8 6 9 7 7 11 15 12 13 9 10 14 11 16 1 17 14 15];
gt=make_graph('foo',1,17,ta,he);
p=[2 16 23 25 26 22 17 18 19 13 10 11];
ns=path_2_nodes(p,gt)
ns =
column 1 to 10
! 1. 10. 15. 16. 17. 14. 11. 12. 13. 9. !
column 11 to 13
! 7. 8. 6. !
// shortest_path
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1];
gt=make_graph('foo',1,15,ta,he);
g1=gt;ma=prod(size(g1('head')));
g1('edge_length')=[13 17 10 6 7 18 18 6 7 14 5 9 5 10 10 2 4 12 15 0 13 4 7 16 11 9 4 16 2];
[p,lp]=shortest_path(13,1,g1,'length')
lp =
24.
p =
! 21. 27. 11. 29. !
// strong_con_nodes
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14];
gt=make_graph('foo',1,15,ta,he);
ncomp=strong_con_nodes(3,gt)
ncomp =
! 1. 2. 3. 4. 5. 6. 7. 8. 9. !
// strong_connex
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14];
gt=make_graph('foo',1,15,ta,he);
[nc,ncomp]=strong_connex(gt)
ncomp =
column 1 to 11
! 3. 3. 3. 3. 3. 3. 3. 3. 3. 2. 1. !
column 12 to 15
! 4. 5. 5. 5. !
nc =
5.
// trans_closure
ta=[2 3 3 5 3 4 4 5 8];
he=[1 2 4 2 6 6 7 7 4];
gt=make_graph('foo',1,8,ta,he);
g1=trans_closure(gt)
g1 =
g1>1
graph
g1>2
foo_trans_closure
g1>3
1.
g1>4
8.
g1>5
column 1 to 11
! 2. 3. 3. 3. 3. 3. 4. 4. 5. 5. 5. !
column 12 to 14
! 8. 8. 8. !
g1>6
column 1 to 11
! 1. 6. 7. 4. 1. 2. 7. 6. 7. 1. 2. !
column 12 to 14
! 6. 7. 4. !
g1>7
[]
g1>8
[]
g1>9
[]
g1>10
[]
g1>11
[]
g1>12
[]
g1>13
[]
g1>14
[]
g1>15
[]
g1>16
[]
g1>17
[]
g1>18
[]
g1>19
[]
g1>20
[]
g1>21
[]
g1>22
[]
g1>23
[]
g1>24
[]
g1>25
[]
g1>26
[]
g1>27
[]
g1>28
[]
g1>29
[]
g1>30
[]
g1>31
[]
g1>32
[]
g1>33
[]
g1>34
[]